package com.vhuan.self_discipline_service.interceptor;

import cn.hutool.jwt.JWT;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
@RequiredArgsConstructor
public class JWTInterceptor implements HandlerInterceptor {
    @Value("${jwt.key}")
    private String JWT_KEY;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        byte[] bytes = JWT_KEY.getBytes();
        return JWT.of(token).setKey(bytes).validate(0);
    }
}
